{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/article/index')}">文章管理</a></li>
            <li class=""><a href="{:url('admin/article/add')}">添加文章</a></li>
            <li class="layui-this">编辑文章</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/article/update')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属栏目</label>
                        <div class="layui-input-block">
                            <select name="cid" lay-verify="required">
                                {foreach name="category_level_list" item="vo"}
                                <option value="{$vo.id}" {if condition="$article.cid==$vo.id"} selected="selected"{/if}>{neq name="vo.level" value="1"}|{php}for($i=1;$i<$vo['level'];$i++){echo ' ----';}{/php}{/neq} {$vo.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" value="{$article.title}" required  lay-verify="required" placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">作者</label>
                        <div class="layui-input-block">
                            <input type="text" name="author" value="{$article.author}" placeholder="（选填）请输入作者" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">简介</label>
                        <div class="layui-input-block">
                            <textarea name="introduction" placeholder="（选填）请输入简介" class="layui-textarea">{$article.introduction}</textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <textarea name="content" lay-verify="content" placeholder="" class="layui-textarea" id="content">{$article.content}</textarea>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">下载链接</label>
                            <div class="layui-input-inline" style="width: 200px;">
                                <input type="text" name="down_link" value="{$article.down_link}" placeholder="（选填）请输入下载链接" class="layui-input">
                            </div>
                            
                            <label class="layui-form-label">下载密码</label>
                            <div class="layui-input-inline" style="width: 200px;">
                                <input type="text" name="down_pas" value="{$article.down_pas}" placeholder="（选填）请输入下载密码" maxlength="4" class="layui-input">
                            </div>
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">缩略图</label>
                        <div class="layui-input-block">
                            <input type="text" style="width:50%;" name="thumb" value="{$article.thumb}" placeholder="请上传缩略图" class="layui-input layui-input-inline" id="thumb">
                            <input type="file" name="file" class="layui-upload-file">
                            
                        </div>
                    </div>
                    
                    <fieldset class="layui-elem-field">
                        <legend>标签数量需要跟拼音数量相同！</legend>
                        <br/>
                            <div class="layui-form-item">
                               <div class="layui-inline">
                                   <label class="layui-form-label">标签</label>
                                   <div class="layui-input-inline" style="width: 320px;">
                                     <input type="text" name="labels" value="{$labels}" placeholder="请输入标签 用英文,隔开" autocomplete="off" class="layui-input">
                                   </div>
                                   <div class="layui-form-mid"></div>
                                   <div class="layui-input-inline" style="width: 320px;">
                                     <input type="text" name="pingying" value="{$pingying}" placeholder="请输入拼音 用英文,隔开" autocomplete="off" class="layui-input">
                                   </div>
                                 </div>
                           </div>
                      </fieldset>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">加入专题</label>
                        <div class="layui-input-block">
                            <input type="text" name="key" value="" placeholder="（选填）请输入专题关键字" class="layui-input key">
                        </div>
                    </div>
                    
                    <div class="layui-form-item ckeck" style='display:none'>
                        <label class="layui-form-label">复选框</label>
                        <div class="layui-input-block" id='check'>
                          
                        </div>
                    </div>
                    
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="已审核" {if condition="$article.status==1"} checked="checked"{/if}>
                            <input type="radio" name="status" value="0" title="未审核" {if condition="$article.status==0"} checked="checked"{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">头条</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_top" value="1" title="是" {if condition="$article.is_top==1"} checked="checked"{/if}>
                            <input type="radio" name="is_top" value="0" title="否" {if condition="$article.is_top==0"} checked="checked"{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">推荐</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_recommend" value="1" title="是" {if condition="$article.is_recommend==1"} checked="checked"{/if}>
                            <input type="radio" name="is_recommend" value="0" title="否" {if condition="$article.is_recommend==0"} checked="checked"{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">首页幻灯</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_slide" value="1" title="是" {if condition="$article.is_slide==1"} checked="checked"{/if}>
                            <input type="radio" name="is_slide" value="0" title="否" {if condition="$article.is_slide==0"} checked="checked"{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">医院</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_yiyuan" value="1" title="是" {if condition="$article.is_yiyuan==1"} checked="checked"{/if}>
                            <input type="radio" name="is_yiyuan" value="0" title="否" {if condition="$article.is_yiyuan==0"} checked="checked"{/if}>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">排序</label>
                        <div class="layui-input-block">
                            <input type="text" name="sort" value="{$article.sort}" required  lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">文章关键字</label>
                        <div class="layui-input-block">
                            <input type="text" name="keyword" placeholder="文章搜索关键字 用英文半角,隔开 例如 朱总,国际" value="{$article.keyword}"  class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="id" value="{$article.id}">
                            <button class="layui-btn" lay-submit lay-filter="*">更新</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script src="__JS__/kindeditor/kindeditor.config.js"></script>
<script src="__JS__/kindeditor/kindeditor-all-min.js"></script>
{/block}
{block name="script"}
<script>
    
    $(function(){
        
        $('#check').on('click','div',function(){
            if($(this).hasClass('layui-form-checked')){
                $(this).removeClass('layui-form-checked').prev().prop({checked:false});
            }else{
                $(this).addClass('layui-form-checked').prev().prop({checked:true});
            }
        })
        
        $('.key').on('blur',function(){
            var key = $(this).val();

            //获取该关键字的文章
            $.getJSON('/admin/Article/getSubjectByKey',{key:key},function(data){
                if(data.status ==1){
                    $('.ckeck').show();
                    var html ='';
                    $.each(data.data,function(k,v){
                        html+='<input type="checkbox" value='+v.id+' name="subject[]" title='+v.name+'><div class="layui-unselect layui-form-checkbox"><span>'+v.name+'</span><i class="layui-icon"></i></div>';
                    })
                    $('#check').empty().append(html);
                }else{
                    $('.ckeck').hide();
                    $('#check').empty();
                    layer.msg(data.message);
                }
            })
        })
    }) 
    
    $(document).ready(function () {
        var _kindEditor;
        KindEditor.ready(function(K) {
            _kindEditor = K.create('#content', KindEditorOptions);

            K('#upload-photo-btn').click(function () {
                var photo_list_item = '';
                _kindEditor.loadPlugin('multiimage', function() {
                    _kindEditor.plugin.multiImageDialog({
                        showRemote : false,
                        imageUrl : K('#photo').val(),
                        clickFn : function(data) {
                            $.each(data, function (index, item) {
                                photo_list_item += '<div class="photo-list"><input type="text" name="photo[]" value="' + item.url + '" class="layui-input layui-input-inline">';
                                photo_list_item += '<button type="button" class="layui-btn layui-btn-danger remove-photo-btn">移除</button></div>'
                            });
                            $('#photo-container').append(photo_list_item);
                            _kindEditor.hideDialog();
                        }
                    });
                });
            });
        });

        $('#photo-container').on('click', '.remove-photo-btn', function () {
            $(this).parent('.photo-list').remove();
        });
    });
</script>
{/block}